#include "mq_connection.hpp"

int main()
{
    // 实例化异步工作线程对象
    lywmq::AsyncWorker::ptr awp = std::make_shared<lywmq::AsyncWorker>();
    // 实例化连接对象
    lywmq::Connection::ptr conn = std::make_shared<lywmq::Connection>("127.0.0.1", 8080, awp);
    // 创建信道
    lywmq::Channel::ptr channel = conn->openChannel();
    // 声明交换机&队列
    google::protobuf::Map<std::string, std::string> tmp_map;
    channel->declareExchange("exchange1", lywmq::ExchangeType::TOPIC, true, false, tmp_map);
    channel->declareQueue("queue1", true, false, false, tmp_map);
    channel->declareQueue("queue2", true, false, false, tmp_map);
    // 绑定
    channel->queueBind("exchange1", "queue1", "queue1");
    channel->queueBind("exchange1", "queue2", "news.music.#");
    // 向交换机发布消息
    for (int i = 0; i < 10; i++) 
    {
        lywmq::BasicProperties bp;
        bp.set_id(lywmq::UUIDHelper::uuid());
        bp.set_delivery_mode(lywmq::DeliveryMode::DURABLE);
        bp.set_routing_key("news.music.pop");
        channel->basicPublish("exchange1", &bp, "Hello World-" + std::to_string(i));
    }
    lywmq::BasicProperties bp;
    bp.set_id(lywmq::UUIDHelper::uuid());
    bp.set_delivery_mode(lywmq::DeliveryMode::DURABLE);
    bp.set_routing_key("news.music.sport");
    channel->basicPublish("exchange1", &bp, "Hello World-TOPIC");

    bp.set_routing_key("news.sport");
    channel->basicPublish("exchange1", &bp, "Hello World-no");
    // 关闭信道
    conn->closeChannel(channel);

    return 0;
}